/*
 * Copyright (C) 2011 bus.fm
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.busfm.model;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * @Description This is the class which is used to manage channels.
 * 
 * @author DJ
 * @version 1.0
 * @Date 2011/08/21
 */
public class ChannelList extends ResultEntity implements Serializable{
    private ArrayList<ChannelEntity> channelList;
    private int selected = -1;

    public ChannelList() {
        channelList = new ArrayList<ChannelEntity>();
    }

    public void addList(ChannelEntity channelEntity) {
        if (null != channelEntity) {
            channelList.add(channelEntity);
        }
    }

    public ChannelEntity removePrivateList() {
        if (!channelList.isEmpty()) {
            return channelList.remove(channelList.size() - 1);
        }
        return null;
    }

    public ArrayList<ChannelEntity> getchannelList() {
        return channelList;
    }

    public boolean isEmpty() {
        return channelList.size() == 0;
    }

    public int size() {
        return channelList == null ? 0 : channelList.size();
    }

    public void selectNext() {
        if (!isEmpty()) {
            selected++;
            selected %= channelList.size();
        }
    }

    public void select(int index) {
        if (!isEmpty()) {
            if (index >= 0 && index < channelList.size())
                selected = index;
        }
    }

    public int getSelectedIndex() {
        if (isEmpty()) {
            selected = -1;
        }
        if (selected == -1 && !isEmpty()) {
            selected = 0;
        }
        return selected;
    }

    public ChannelEntity getSelectedEntity() {
        return channelList.get(selected);
    }
}
